package com.wwh.furns.dao.impl;

import com.wwh.furns.dao.BasicDAO;
import com.wwh.furns.dao.OrderItemDAO;
import com.wwh.furns.entity.Order;
import com.wwh.furns.entity.OrderItem;

import java.util.List;

import static com.alibaba.druid.sql.ast.SQLPartitionValue.Operator.List;

/**
 * @author Albert
 * @date 2024/7/31-20:57
 * @describe
 */
public class OrderItemDAOImpl extends BasicDAO<OrderItem> implements OrderItemDAO {
    @Override
    public List<OrderItem> readOrderItemByOrderId(String orderId) {
        String sql = "SELECT id, name, price, count, total_price as totalPrice, order_id as OrderId FROM order_item where order_id = ?";
        return queryMulti(sql, OrderItem.class, orderId);
    }

    @Override
    public int saveOrderItem(OrderItem orderItem) {
        String sql = "INSERT INTO `order_item`(`id`, `name`, `price`, `count`, `total_price`, `order_id`) " +
                "VALUE(?, ?, ?, ?, ?, ?);";
        return update(sql, orderItem.getId(), orderItem.getName(), orderItem.getPrice(), orderItem.getCount(), orderItem.getTotalPrice(), orderItem.getOrderId());
    }
}
